#ifndef __LOG_H__
#define __LOG_H__

// This is a simple log routine that can output log into 
// both standard output and html files. Html log are more
// elegent and can contain more information.

#define RAYLOG_MAXSTR       1024

// the type of a log
#define RAYLOG_TYPE_UNKNOW  0
#define RAYLOG_TYPE_HTML    1
#define RAYLOG_TYPE_STD        2
#define RAYLOG_TYPE_MAX     3

// the level of a log item
#define RAYLOG_LEVEL_COUNT 6
#define RAYLOG_HIGHEST  5
#define RAYLOG_HIGHER   4
#define RAYLOG_HIGH     3
#define RAYLOG_NORMAL   2
#define RAYLOG_LOWER    1
#define RAYLOG_NONE     0

// color used in HTML
#define RAYLOG_RED      0
#define RAYLOG_GREEN    1
#define RAYLOG_BLUE     2
#define RAYLOG_BLACK    3
#define RAYLOG_COLOR_COUNT 4

// format of the log
#define RAYLOG_TITLE        0
#define RAYLOG_HEADER       1
#define RAYLOG_SUBHEADER    2
#define RAYLOG_CONTENT      3
#define RAYLOG_LIST         4
#define RAYLOG_FORMAT_COUNT 5

// Time format
#define RAYLOG_TIME_NONE        0
#define RAYLOG_TIME_RELATIVE    1
#define RAYLOG_TIME_ABSOLUTE    2

// Macros for convenient
#define LOG_TITLE(str)      log_write(str, RAYLOG_TITLE, 3);
#define LOG_HEADER(str)     log_write(str, RAYLOG_HEADER, 3);
#define LOG_SEBHEADER(str)  log_write(str, RAYLOG_SUBHEADER, 3);
#define LOG_CONTENT(str, level)    log_write(str, RAYLOG_CONTENT, level);
#define LOG_LIST(str, level)       log_write(str, RAYLOG_LIST, level);

// Create a log file
void log_init(char* filename, unsigned filetype);

void log_enable();
void log_disable();

// force the program to write log
void log_flush();

// write what you want to the log
void log_write(char* content, unsigned fmttype, unsigned level);

// printf colorful log. for html only
void log_cwrite(char* content, unsigned fmttype, unsigned level, unsigned cltype);

void log_setTimeType(unsigned timetype);

// Release used resources
void log_destory();

#define CHECK_ENABLE() if (!g_enabled) return;

#endif // RAYLOG_H_INCLUDED
